home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / inc_date.arc / inc_date.c next >
C/C++ Source or Header  |  1987-09-10  |  2KB  |  91 lines

  1. /*
  2.    INC_DATE.C
  3.    by Domenico De Vitto (ddv@uk.ac.bton.unix)
  4.    This increments the date at bootup so that make doesn't do odd things...
  5.    (this is the only file)
  6.    Compiled with Heat n Serve C 1.40 on 16/4/93
  7. */
  8. #include <stdio.h>
  9. #include <osbind.h>
  10.  
  11. /* test routine checks that the date is set to d/m/y ie 16/4/1993
  12. void checkdate(d,m,y)
  13. unsigned int d,m,y;
  14. {
  15. unsigned int d2,m2,y2,date;
  16.   date=Tgetdate();
  17.   d2=date & (1+2+4+8+16);
  18.   m2=(date & (32+64+128+256)) >>5;
  19.   y2=(date >> 9)+1980;
  20.   printf("System date now: %u/%u/%u  should be %u/%u/%u  ",d2,m2,y2,d,m,y);
  21.   if (d2!=d || m2!=m || y2!=y)
  22.     { printf("\007\007\007Program failed."); getchar(); }
  23.   putchar('\n');
  24. }
  25. */
  26.  
  27. void main()
  28. {
  29.   FILE *fd;
  30.   unsigned int a,date,d,m,y;
  31.   setbuf(stdin,NULL);
  32.  
  33.   printf("- inc_date v1.10 by D De Vitto 16/4/93 -\n");
  34. /* get date from system */
  35.   date=Tgetdate();
  36.   d=date & (1+2+4+8+16);
  37.   m=(date & (32+64+128+256)) >>5;
  38.   y=(date >> 9)+1980;
  39.   printf(" Current BDOS date : %u/%u/%u\n",d,m,y);
  40.  
  41. /* get date from file */
  42. /* NB for AUTO folder prgs the current directory is the root of the boot
  43.    drive, so normally this file is read/created there.
  44. */
  45.   fd=fopen("inc_date.inf","r");
  46.   if (fd!=NULL)
  47.     {
  48.     fscanf(fd,"%u/%u/%u",&d,&m,&y);
  49.     printf(" Using date info in \"inc_date.inf\" : %u/%u/%u\n",d,m,y);
  50.     }
  51.   fclose(fd);
  52.  
  53. /* increment the date */
  54.  
  55.   if (d<28) d++;
  56.   else
  57.     { d=1;
  58.       if (m<12) m++;
  59.       else
  60.         { m=1;
  61.           if (y<2050) y++;
  62.           else y=1993;
  63.         }
  64.     }
  65.  
  66.  
  67. /* set the date into the system */
  68.   printf(" Setting date to : %u/%u/%u\n",d,m,y);
  69.   date=((y-1980) << 9) + (m << 5) + d;
  70.   Tsetdate(date);
  71.  
  72. /* check was right... */
  73. /*  checkdate(d,m,y); */
  74.  
  75. /* save the date to file */
  76.   printf(" Saving date to \"inc_date.inf\" ... ");
  77.   fd=fopen("inc_date.inf","w");
  78.   if (fd!=NULL)
  79.     {
  80.     fprintf(fd,"%u/%u/%u\n",d,m,y);
  81.     printf("Done.\n");
  82.     fclose(fd);
  83.     }
  84.   else
  85.     {
  86.     printf("\007\007unable to open file.\n");
  87.     fclose(fd);
  88.     }
  89. }
  90.  
  91.